
#ifndef CONFERENCEMODULE_H 
#define CONFERENCEMODULE_H

#include <mipvideosession.h>
#include <mipavcodecencoder.h>
#include <mipaudiosession.h>
#include <iostream>
#include <rtpipv4address.h>

#include <iostream>
using namespace std;

#include <qthread.h>

class MyAudioSession : public MIPAudioSession
{
protected:
	void onInputThreadExit(bool err, const std::string &compName, const std::string &errStr)
	{
		if (err)
		{
			std::cerr << "Input chain thread exited due to an error" << std::endl;
			std::cerr << "Component: " << compName << std::endl;
			std::cerr << "Error: " << errStr << std::endl;
		}
		else
		{
			std::cout << "InputThread finished without errors..." << std::endl;
		}
	}
	void onOutputThreadExit(bool err, const std::string &compName, const std::string &errStr)
	{
		if (err)
		{
			std::cerr << "Output chain thread exited due to an error" << std::endl;
			std::cerr << "Component: " << compName << std::endl;
			std::cerr << "Error: " << errStr << std::endl;
		}
		else
		{
			std::cout << "OutputThread finished without errors..." << std::endl;
		}
	}	
};

class ConferenceModule : public QThread
{
public:
	ConferenceModule(int toggle, int basePort, int port, uint8_t *ip);
	ConferenceModule(){usedCodec = 1;}
	~ConferenceModule(void);

	virtual void run();
	// check functies
	void checkRet(bool ret,const MIPErrorBase &obj);

	int startSending();
	int startReceiving();

	// setfuncties
	void setPort(int port){m_port = port;}
	void setBasePort(int port){m_basePort = port;}
	void setMode(int mode){m_mode = mode; } // 1 = send, 2 = receive

	void setCodec(int codecNr);

	void setIp(uint8_t ip[4])
	{	
		m_ip[0] = ip[0];
		m_ip[1] = ip[1];
		m_ip[2] = ip[2];
		m_ip[3] = ip[3];
	}


private:
	int m_mode; // 1 = send, 2 = receive
	int m_basePort;
	int m_port;
	uint8_t m_ip[4];
	MyAudioSession * audioSess;

	int usedCodec;

};

#endif